﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Power.Model;
using Power.DAL;

namespace Power
{
    /// <summary>
    /// EditCus.xaml 的交互逻辑
    /// </summary>
    public partial class EditCus : Window
    {
        public EditCus()
        {
            InitializeComponent();
        }

        public long IDtemp
        {
            get;
            set;
        }

        public string CUSname
        {
            get;
            set;
        }

        public string CID
        {
            get;
            set;
        }

        public string Address
        {
            get;
            set;
        }

        public string Phone
        {
            get;
            set;
        }

        public string Device
        {
            get;
            set;
        }


        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            CIDbox.Text = CID;
            Addbox.Text = Address;
            Cusnamebox.Text = CUSname;
            Devicebox.Text = Device;
            Phonebox.Text = Phone;
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {






            bool isOK = true;



            string cusnat = Cusnamebox.Text;
            string addresst = Addbox.Text ;
            string phonet = Phonebox.Text;
            string cidt = CIDbox.Text;
            string decivet = Devicebox.Text;



            CheckTextboxNotEmpty(ref isOK, Cusnamebox, Addbox, Phonebox, CIDbox, Devicebox);
            if (!isOK)
            {
                MessageBox.Show("有未填写信息");
                return;
            }



            Customer op = new Customer();

            op.CusName = cusnat;
            op.Address = addresst;
            op.CID = cidt;
            op.Device = decivet;
            op.Phone = phonet;

            new CustomerDAL().CusUpdate(IDtemp,op.CusName,op.Address,op.Device,op.CID,op.Phone);
            MessageBox.Show("修改成功");
            DialogResult = false;

















        }




        private void CheckTextboxNotEmpty(ref bool isOK,
params TextBox[] textboxes)
        {
            foreach (TextBox txtBox in textboxes)
            {
                if (txtBox.Text.Length <= 0)
                {
                    isOK = false;
                    txtBox.Background = Brushes.Red;
                }
                else
                {
                    txtBox.Background = null;
                }
            }
        }

        private void CheckPassboxNotEmpty(ref bool isOK,
params PasswordBox[] passes)
        {
            foreach (PasswordBox passBox in passes)
            {
                if (passBox.Password.Length <= 0)
                {
                    isOK = false;
                    passBox.Background = Brushes.Red;
                }
                else
                {
                    passBox.Background = null;
                }
            }
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
        }











    }
}
